
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" lay-filter="demo2">
            <input type="hidden" name="id" value="${admin.id}" lay-verify="required" autocomplete="off" class="layui-input">
            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input type="text" name="account" lay-verify="required|account_" autocomplete="off" placeholder="请输账号" class="layui-input" >
                </div>
            </div>
<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label">密码</label>--%>
<%--                <div class="layui-input-block">--%>
<%--                    <input type="text" name="password" lay-verify="required|pass" autocomplete="off" placeholder="请输入密码" class="layui-input" >--%>
<%--                </div>--%>
<%--            </div>--%>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name"  autocomplete="off" placeholder="请输入您的姓名（可省略）" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="remark"  autocomplete="off" placeholder="请输入备注信息（可省略）" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>

                </div>
            </div>
        </form>
    </div>
</div>

<script src="../static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate,
        $=layui.jquery;


        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,15}$/
                , '密码须6到15位，且不能出现空格'
            ],
            account_: [
                /^[\S]{5,15}$/
                , '用户名须5到15位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            $.ajax({
                url:"update",
                method:"POST",
                contentType:"application/json",
                dataType:"json",
                data:JSON.stringify(data.field),
                success:function (data) {
                    if(data.code==0){
                        layer.msg("修改成功",{time:1000},function () {
                            window.parent.location.reload();
                        });
                    }else {
                        layer.msg("修改失败",{time:1000},function () {
                            layer.close(layer.index);
                        });
                    }
                }
            });
            return false;
        });

        //表单初始赋值
        form.val('demo2', {
          "account": "${admin.account}"
            <%--, "password": "${admin.password}"--%>
            , "name": "${admin.name}"
            , "remark": "${admin.remark}"
        });

    });

</script>

</body>
</html>
